package zuosheng.string;

/**
 * @author lj
 * @Description: 判断两个字符串是否为变词
 * @date 2020-11-15 14:07
 * @QQ 851477108
 */


public class Deformation {
    public static void main(String[] args) {
        String a = "123";
        String b = "231";
        System.out.println(isDeformation(a,b));
    }

    public static boolean isDeformation(String a, String b){
        if (a == null || b == null || a.length() != b.length()){
            return false;
        }

        int[] map = new int[256];
        char[] chars1 = a.toCharArray();
        char[] chars2 = b.toCharArray();

        for (int i = 0; i < chars1.length; i++){
            map[chars1[i]]++;
        }

        for (int i = 0; i < chars1.length; i++){
            if (map[chars2[i]]-- == 0){
                return false;
            }
        }
        return true;
    }
}
